# -*- coding: utf-8 -*-
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from datetime import timedelta
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dwd.dwd_warhouse.dwd_wide_sign_summary_waybill_dt import jms_dwd__dwd_wide_sign_summary_waybill_dt
from jms.dim.sqs.dim_problem_express_wo_record_base import jms_dim__dim_problem_express_wo_record_base
from jms.dwd.tab.dwd_tab_barscan_taking_base_dt import jms_dwd__dwd_tab_barscan_taking_base_dt
from jms.dwd.tab.dwd_tab_barscan_arrival_base_dt import jms_dwd__dwd_tab_barscan_arrival_base_dt
from jms.dwd.tab.dwd_tab_barscan_warehousing_base_dt import jms_dwd__dwd_tab_barscan_warehousing_base_dt
from jms.dwd.tab.dwd_barscan_bagging_dt import jms_dwd__dwd_barscan_bagging_dt
from jms.time_sensor.time_after_07_30 import time_after_07_30
from jms.dwd.tab.dwd_tab_barscan_centersend_base_dt import jms_dwd__dwd_tab_barscan_centersend_base_dt
from jms.dwd.tab.dwd_tab_barscan_centerarrival_base_dt import jms_dwd__dwd_tab_barscan_centerarrival_base_dt

jms_dm__dm_outport_bagging_fine_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_outport_bagging_fine_detail_dt',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    execution_timeout=timedelta(minutes=30),
    email=['matthew.xiong@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_outport_bagging_fine_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_outport_bagging_fine_detail_dt/execute.hql',
    driver_memory='8G',
    driver_cores=4,
    executor_cores=4,
    executor_memory='16G',
    num_executors=30,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled' : 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'  : 45,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.sql.sources.partitionOverwriteMode' : 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'  : '2G',  # 堆外内存
        'spark.sql.shuffle.partitions'  : 800,
    },
    hiveconf={
        'hive.exec.dynamic.partition' : 'true',  # 动态分区
        'hive.exec.dynamic.partition.mode' : 'nonstrict',
        'hive.exec.max.dynamic.partitions' : 100,
        'hive.exec.max.dynamic.partitions.pernode': 100,
    },
)

jms_dm__dm_outport_bagging_fine_detail_dt << [
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_tab_barscan_taking_base_dt,
    jms_dwd__dwd_tab_barscan_arrival_base_dt,
    jms_dwd__dwd_tab_barscan_warehousing_base_dt,
    jms_dwd__dwd_barscan_bagging_dt,
    jms_dwd__dwd_wide_sign_summary_waybill_dt,
    jms_dim__dim_problem_express_wo_record_base,
    jms_dwd__dwd_tab_barscan_centersend_base_dt,
    jms_dwd__dwd_tab_barscan_centerarrival_base_dt,
    time_after_07_30
]
